package com.xiguaji.tiktok.v1.tiktok.music.repository.impl;

import com.xiguaji.boot.toolkit.jdbc.JdbcTemplateHelper;
import com.xiguaji.tiktok.v1.tiktok.music.repository.MusicExtRepository;

import java.util.List;
import java.util.Map;

public class MusicExtRepositoryImpl implements MusicExtRepository {

    @Override
    public List<Map<String, Object>> getRegionDistribution(long musicId, long beforeDaySecond) {
        StringBuilder sql = new StringBuilder();
        sql.append("select count(*) as count,r.name as name ");
        sql.append("from aweme a left join region r on a.o_region = r.code ");
        sql.append("where a.o_music_id = ? and a.o_create_time > ? ");
        sql.append("GROUP BY a.o_region ORDER BY count desc ");
        List<Map<String, Object>> mapList = JdbcTemplateHelper.select(sql.toString(),musicId,beforeDaySecond);
        return mapList;
    }

    @Override
    public List<Map<String, Object>> getIndustryDistribution(long musicId, long beforeDaySecond) {
        StringBuilder sql = new StringBuilder();
        sql.append("select count(*) as count,a.blogger_type as name ");
        sql.append("from aweme a ");
        sql.append("where a.o_music_id = ? and a.o_create_time > ? ");
        sql.append("GROUP BY a.blogger_type ORDER BY count desc ");
        List<Map<String, Object>> mapList = JdbcTemplateHelper.select(sql.toString(),musicId,beforeDaySecond);
        return mapList;
    }
}
